/* Utility scripts for Pardus Sector Tool
 * (C) Yassen 2009
 *
 * tile.js
 * Defines functions for getting/setting tile information information.
 *
 * Functions:
 * array  GetSelected()
 * void   Select(id)
 * void   DeSelect(id)
 * bool   IsSelected(id)
 * Tile   Get(id)
 *
 */

Utility.Tile.GetSelected = function(object)
{
  var tiles = Global.SectorList[Global.CurrentSector].tiles;
  var results = [];

  if (object == undefined) // Slow
  {
    for (var i = 0; i < tiles.length; i++)
    {
      var tile = tiles[i];

      if (tile.selected)
        results.push(tile);
    }
  }
  else // Fast
  {
    var objectList = Utility.Object.GetList(object);

    for (var i = 0; i < objectList.length; i++)
    {
      var obj = objectList[i];

      if (tiles[obj.id].selected)
        results.push(tiles[obj.id]);
    }
  }
  return results;
}

Utility.Tile.Select = function(id)
{
  Global.SectorList[Global.CurrentSector].tiles[id].selected = true;
  $("nav_" + id).setAttribute("class", "selected");
}

Utility.Tile.DeSelect = function(id)
{
  Global.SectorList[Global.CurrentSector].tiles[id].selected = false;
  $("nav_" + id).setAttribute("class", TileTypeToAbbr(Global.SectorList[Global.CurrentSector].tiles[id].type));
}

Utility.Tile.IsSelected = function(id)
{
  return Global.SectorList[Global.CurrentSector].tiles[id].selected;
}

Utility.Tile.Get = function(id)
{
  return Global.SectorList[Global.CurrentSector].tiles[id];
}